﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Reflection;

namespace StockTrader.DAL.HnxMonitor.Config
{
    public static class Settings
    {
        public static int TRADING_INTERVAL = Convert.ToInt32(ConfigurationManager.AppSettings["INTERVAL"]);
        public static int STATUS_CHECK_INTERVAL = Convert.ToInt32(ConfigurationManager.AppSettings["STATUS_CHECK_INTERVAL"]);
        public static string DAL_ORAC = ConfigurationManager.AppSettings["DAL_ORAC"].ToString();
        public static string DAL_MYSQL = ConfigurationManager.AppSettings["DAL_MYSQL"].ToString();
        public static string UPDATE_LIST = ConfigurationManager.AppSettings["UPDATE_LIST"].ToString();

        public static DateTime BOD = Convert.ToDateTime(ConfigurationManager.AppSettings["BoD"].ToString());
        public static DateTime EOD = Convert.ToDateTime(ConfigurationManager.AppSettings["EoD"].ToString());


        public static string CNN_HNX_ORACLE = ConfigurationManager.ConnectionStrings["HnxOracle"].ToString();
        public static string CNN_HNX_MYSQL = ConfigurationManager.ConnectionStrings["HnxMySQL"].ToString();

        public static void UpdateSetting(string key, string value, string section)
        {
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            switch (section)
            {
                case "ConnectionStrings":
                    config.ConnectionStrings.ConnectionStrings.Remove(key);
                    config.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings(key, value));
                    break;
                case "AppSettings":
                    config.AppSettings.Settings[key].Value = value;
                    break;
            }
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection(section);
        }

    }
}
